package com.fp.m7.shared.validator;

import org.springframework.stereotype.Component;

import com.fp.m7.shared.ValidationConstants;
import com.fp.m7.shared.ValidationError;
import com.fp.m7.shared.ValidationResult;

@Component
public class StatusAndDescriptionValidator {

    public ValidationResult validate(String status, String description) {
        ValidationResult result = validateStatus(status);

        result.addAll(validateDescription(description));
        
        return result;
    }

    public ValidationResult validateStatus(String status) {
        ValidationResult result = new ValidationResult();

        if (status != null && !status.matches(ValidationConstants.STATUS_REGEX)) {
            result.add(new ValidationError(ValidationConstants.Fields.STATUS, ValidationConstants.Messages.REGEX_FAIL));
        }

        return result;
    }

    public ValidationResult validateDescription(String description) {
        ValidationResult result = new ValidationResult();

        if (description != null && !description.matches(ValidationConstants.DESCRIPTION_REGEX)) {
            result.add(new ValidationError(ValidationConstants.Fields.DESCRIPTION,
                    ValidationConstants.Messages.REGEX_FAIL));
        }

        return result;
    }

}
